﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Ccit.OA.MsPersonDoc;
using Newtonsoft.Json;
using System.Collections.Generic;
using Ccit.Utils;
namespace Ccit.OA.PersonDoc
{
    public partial class persondoc_folder_edit : Ccit.Utils.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                _hidFId.Value = (null != Request.QueryString["FId"]) ? Request.QueryString["FId"].ToString() : "";
                _hidSuperiorId.Value = (null != Session["folderID"]) ? Session["folderID"].ToString().Trim() : "0";
                _hidUserId.Value = (null != Session["UserIdShare"]) ? Session["UserIdShare"].ToString().Trim() : "";
                
                initializePage();
            }
        }

        private void initializePage()
        {
            LoginUser loginUser = Session["LogUserInfo"] as LoginUser;
            if (_hidUserId.Value == "")
             { 
                   _hidUserId.Value = loginUser.UserId;
             }

                
            //ViewState["Type"]  1更新、0增加
            if (_hidFId.Value.Trim() != "")
            {
                PersonDocBLL bll = new PersonDocBLL();
                MsFolder ms = new MsFolder();
                ms.UserId = _hidUserId.Value;

                ms.FId = _hidFId.Value.Trim();
                DataSet dSet = bll.GetPersonDocfolder(ms, " and DOC_A1_10=" + ms.FId,"1");
                if (dSet.Tables[0].Rows.Count != 0)
                {
                    txtName.Text = dSet.Tables[0].Rows[0]["DOC_A1_20"].ToString().Trim();
                    if (dSet.Tables[0].Rows[0]["DOC_A1_50"].ToString().Trim() == "1")
                    {
                        radioList.Items[1].Selected = true;
                        radioList.Items[0].Selected = false;
                    }
                    /*只读共享设置*/
                    txtRead.Text = Utils.SysInterface.GetNameStrByIdStr(dSet.Tables[0].Rows[0]["DOC_A1_70"].ToString().Trim(), dSet.Tables[0].Rows[0]["DOC_A1_60"].ToString().Trim(), " ");
                    _hidReadId.Value = dSet.Tables[0].Rows[0]["DOC_A1_70"].ToString().Trim();
                    _hidReadMark.Value = dSet.Tables[0].Rows[0]["DOC_A1_60"].ToString().Trim();
                    
                    /*完全共享设置*/
                    txtCompletey.Text = Utils.SysInterface.GetNameStrByIdStr(dSet.Tables[0].Rows[0]["DOC_A1_90"].ToString().Trim(), dSet.Tables[0].Rows[0]["DOC_A1_80"].ToString().Trim(), " ");
                    _hidCompleteyId.Value = dSet.Tables[0].Rows[0]["DOC_A1_90"].ToString().Trim();
                    _hidCompleteyMark.Value = dSet.Tables[0].Rows[0]["DOC_A1_80"].ToString().Trim();


                    /*获取上级文件夹的路径*/
                    _hidUrl.Value = dSet.Tables[0].Rows[0]["url"].ToString().Trim();
                }

                bll.Release();
                bll = null;
                ms = null;

                //btnBack.Style.Add("display", "none");
                //btnSaveBack.Style.Add("display", "none");
            }
        
            btnClose.Style.Add("display", "none");
        }

        #region Ajax Methods
        [global::System.Web.Services.WebMethod]
        public static string DoSave(string jsonExpr, string cType)
        {
            PersonDocBLL Bll = new PersonDocBLL();
            MsFolder ms = (MsFolder)JavaScriptConvert.DeserializeObject(jsonExpr, typeof(MsFolder));
            List<string> lstResult = Bll.DoSaveFloderMess(ms);

            var newObj = new { resultID = lstResult[0], message = lstResult[1], ctrtype = lstResult[2], Superiorid = lstResult[4], FName = lstResult[3], OperateType = cType };
            string serExpr = JavaScriptConvert.SerializeObject(newObj);
            Bll = null;
            newObj = null;
            return serExpr;
        }
        #endregion
    }
}
